import { Effect, Reducer, Subscription } from 'umi';
import { getMessage, getRead } from "@/services";
export interface IndexModelState {
    name: string,
    list: string,
}
export interface IndexModelType {
    namespace: 'msgboard';
    state: IndexModelState;
    effects: {
        getMessage: Effect;
        getRead: Effect;
    };
    reducers: {
        msg: Reducer<IndexModelState>;
    };
    subscriptions?: { setup: Subscription };
}
const Message: IndexModelType = {
    namespace: 'msgboard',
    state: {
        name: '',
        list: ''
    },
    effects: {
        //评论列表数据
        *getMessage({ payload }, { call, put }) {
            let res = yield call(getMessage);
            yield put({
                type: "msg",
                payload: {
                    name: res
                }
            })
        },
        //推荐阅读
        *getRead({ payload }, { call, put }) {
            let result = yield call(getRead);
            yield put({
                type: "msg",
                payload: {
                    list: result
                }
            })
        }
    },
    reducers: {
        msg(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        }
        // 启用 immer 之后
        // save(state, action) {
        //   state.name = action.payload;
        // },
    },
};

export default Message;